package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.domain.BProjectUser;
import com.ruoyi.system.domain.vo.BUserVo;
import com.ruoyi.system.service.BProjectUserService;
import com.ruoyi.system.mapper.BProjectUserMapper;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author yangxingze
* @description 针对表【b_project_user(项目用户关联表)】的数据库操作Service实现
* @createDate 2025-01-03 01:23:19
*/
@Service
public class BProjectUserServiceImpl extends ServiceImpl<BProjectUserMapper, BProjectUser>
    implements BProjectUserService{

    /**
     * 根据项目id删除项目用户
     * @param projectId
     */
    @Override
    public void deleteProjectUserByProjectId(Long projectId) {
        baseMapper.deleteProjectUserByProjectId(projectId);
    }

    /**
     * 保存项目用户
     * @param userList
     * @param projectId
     */
    @Override
    public void saveProjectUser(List<BUserVo> userList, Long projectId) {
        if(ObjectUtils.isNotEmpty(userList)){
            for(BUserVo user:userList){
                BProjectUser projectUser = new BProjectUser();
                projectUser.setDoctorId(user.getId());
                projectUser.setProjectId(projectId);
                projectUser.setType(user.getRoleType());
                projectUser.setCreateTime(new Date());
                this.save(projectUser);
            }
        }
    }
}




